package com.atguigu.system.controller;


import com.atguigu.model.vo.LoginVo;
import com.atguigu.system.service.SysUserService;
import com.atguigu.system.utils.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "用户登录接口")
@RestController
@CrossOrigin
@RequestMapping("/admin/system/index")
public class UserLoginController {

    @Resource
    private SysUserService sysUserService;

    // login
    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo, HttpServletRequest request) {

        // 进行登录
        String token = sysUserService.login(loginVo, request);

        Map<String, Object> map = new HashMap<>();
        map.put("token", token);
        return R.ok().put("data", map);
    }

    // 用户信息接口
    @GetMapping("info")
    public R info(HttpServletRequest request) {
        Map<String, Object> map = sysUserService.info(request);
//        Map<String, String> map = new HashMap<>();
       /* map.put("roles","admin");
        map.put("introduction", "I am a super administrator");
        map.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        map.put("name", "Super Admin");*/
        return R.ok().put("data", map);
    }

    /**
     * 退出
     * @return
     */
    @PostMapping("/logout")
    public R logout(){
        // 登出
        sysUserService.logout();
        return R.ok();
    }
}
